package c.x.jy.service.service.impl;

import c.x.jy.dao.dto.OrderCommisionEntityDto;
import c.x.jy.dao.entity.BusinessEntity;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.dao.entity.TeacherEntity;
import c.x.jy.service.service.BusinessService;
import c.x.jy.service.service.MemberService;
import c.x.jy.service.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.Query;

import c.x.jy.dao.dao.OrderCommisionDao;
import c.x.jy.dao.entity.OrderCommisionEntity;
import c.x.jy.service.service.OrderCommisionService;
import org.apache.commons.lang3.StringUtils;


@Service("orderCommisionService")
public class OrderCommisionServiceImpl extends ServiceImpl<OrderCommisionDao, OrderCommisionEntity> implements OrderCommisionService {
    @Autowired
    BusinessService businessService;
    @Autowired
    TeacherService teacherService;
    @Autowired
    MemberService memberService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        	QueryWrapper<OrderCommisionEntity> query= 	 new QueryWrapper<OrderCommisionEntity>() ;
    	if(params.get("searchKey")!=null&&params.get("searchValue")!=null&&!StringUtils.isEmpty(params.get("searchKey").toString())&&!StringUtils.isEmpty(params.get("searchValue").toString()))
    	    query.eq(  params.get("searchKey").toString(), params.get("searchValue"));
        if(params.get("businessId")!=null) 	query.eq("payee_id", params.get("businessId"));
//        IPage<OrderCommisionEntity> page = this.page(
//                new Query<OrderCommisionEntity>().getPage(params),
//                 query
//        );
        IPage<OrderCommisionEntityDto> page =   this.getBaseMapper().querypage(new Query<OrderCommisionEntity>().getPage(params),  query);
        return new PageUtils(page);
    }

    @Override
    public String queryCommisionPartName(Integer payeeType, Long payeeId) {
        String partName="无";
        if(payeeType.equals(0))
            partName = "平台";
        else if(payeeType.equals(1)){
            //商家
            if(payeeId!=null){
                BusinessEntity businessEntity = businessService.getById(payeeId);
                if(businessEntity!=null){
                    partName = businessEntity.getName();
                }else{
                    partName="无";
                }
            }

        }else if(payeeType.equals(2)){
            //专家
            if(payeeId!=null){
                TeacherEntity teacherEntity = teacherService.getById(payeeId);
                if(teacherEntity!=null){
                    partName = teacherEntity.getNickname();
                }else{
                    partName="无";
                }
            }

        }else if(payeeType.equals(3)){
            //会员
            if(payeeId!=null){
                MemberEntity memberEntity = memberService.getById(payeeId);
                if(memberEntity!=null){
                    partName = memberEntity.getNickname();
                }else{
                    partName="无";
                }
            }
        }
        return partName;
    }

}
